package cn.wolfcode.crm.domain;

import com.alibaba.fastjson.JSON;import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;import java.util.HashMap;import java.util.Map;

/**
 * 客户移交历史
 */
@Setter
@Getter
public class CustomerTransfer {
    private Long id;
    //客户
    private Customer customer;
    //操作人
    private Employee operator;
    //操作时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date operateTime;
    //旧销售人
    private Employee oldseller;
    //新销售人
    private Employee newseller;
    //移交
    private String reason;

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", this.id);
        map.put("reason", this.reason);
        map.put("operateTime", this.operateTime);
        if (this.customer != null) {
            map.put("customerName", this.customer.getName());
            map.put("customerId", this.customer.getId());
        }
        if (this.operator != null) {
            map.put("operatorName", this.operator.getName());
            map.put("operatorId", this.operator.getId());
        }
        if (this.oldseller != null) {
            map.put("oldsellerName", this.oldseller.getName());
            map.put("oldsellerId", this.oldseller.getId());
        }
        if (this.newseller != null) {
            map.put("newsellerName", this.newseller.getName());
            map.put("newsellerId", this.newseller.getId());
        }
        return JSON.toJSONString(map);
    }

}